<!-- Study_CompetitiveProductsCommentList.html -->
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
		<title>精品课程评论列表</title>
		<link rel="stylesheet" type="text/css" href="../../css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/weibo.css">
		<link rel="stylesheet" href="../../css/CFNetPP_Base.css">
		<link rel="stylesheet" href="../../css/base.css">
		<link rel="stylesheet" type="text/css" href="../../css/study.css" />
		<style type="text/css">
			.bottom-div{
	        	height: 50px;
	        	padding: 10px;
	        	background-color: white;
	        	position: fixed;
	        	left: 0;
	        	bottom: 0;
	        	width: 100%;
	        }
	        .bottom-div .bottom-div-content{
	        	background-color: #f0f0f0;
	        	border: 1px solid #d9d9d9;
	        	border-radius: 3px;
	        	padding: 1px 10px;
	        	height: 30px;
	        }
	        .bottom-div .bottom-div-title{
	        	font-size: 14px;
	        	color: #999;
	        	line-height: 14px;
	        	margin-left: 20px;
	        }
	        .bottom-div .bottom-div-icon{
	        	width: 16px;
	        	position: absolute;
	        	left: 20px;
	        	top: 17px;
	        }
	        .bottom-blank-div{
	        	height: 50px;
	        }
	        .float-right-span{
	        	float: right;
	        	font-size: 12px;
	        	color: #999;
	        }
	        .delete-img{
	        	width: 14px;
	        	position: relative;
	        	top: 2px;
	        	left: -2px;
	        }
		</style>
	</head>
	<body>
	<body >
		<div class=" writeReport">
			<div class="ReviewWeekly_div">
				<ul class="mui-table-view " id="list_discus" style="height: 90%">
					<!-- <li class="mui-table-view-cell mui-media list_item">
						<img class="mui-media-object mui-pull-left cell_user_icon2" src="../../image/icon_touxiang.png" style="display: block">
						<p class="base_content_font base_dark_grey">
							<span>李旭日</span>
							<span class="font10 left_5">2017.10.20</span>
							<span class="float-right-span">
								<img class="delete-img" src="../../image/icon_shanchu.png"/>
								<span>删除</span>
							</span>
						</p>
						<div class="clearfix">
							<div class="star left" id="taiduNum">
								<img src="../../image/icon_xingxing.png" style="height: 14px">
								<img src="../../image/icon_xingxing.png" style="height: 14px">
								<img src="../../image/icon_xingxing.png" style="height: 14px">
								<img src="../../image/icon_xingxing.png" style="height: 14px">
								<img src="../../image/icon_xingxing.png" style="height: 14px">
							</div>
						</div>
						<div class="Commentbody top_2 ">
							<p>
								有一件事我什么都没干，错了怪我吗
							</p>
						</div>
					</li> -->
				</ul>
			</div>
			<div class="noSign" hidden="hidden" id="noData">
				<img src="../../image/icon_img.png" width="60%">
				<p class="font16 top_15 base_dark_grey" >
					暂无评论
				</p>
			</div>
			<div class="loadFailure" hidden="hidden" id="noNet">
				<img src="../../image/icon_img01.png" width="60%">
				<p class="" >
					数据加载失败
				</p>
				<p>
					请检查您的网络
				</p>
				<button type="button" class="mui-btn mui-btn-outlined" onclick="RefreshData()">
					重新加载
				</button>
			</div>
			<div class="bottom-div mui-table-view" onclick="onEditCommentClick()">
				<div class="bottom-div-content">
					<img class="bottom-div-icon" src="../../image/icon_bottom_edit.png">
					<span class="bottom-div-title">
						我要评论
					</span>
				</div>
			</div>
			<div class="bottom-blank-div"></div>
		</div>
	</body>
	<script type="text/javascript" src="../../script/jquery.min.js"></script>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script src="../../script/jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script src="../../script/common.js"></script>
	<script src="../../script/timeStampTool.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript">
		var page = 1;
		var row = 10;
		//更新数据条数
		var refreshCount = 0;
		var dataArr = new Array();
		var pid = "";
		// 计划id
		var cid = "";
		//课程id
		var title = "";
		//被点击的题目id
		var Itemid = "";
		//章节id
		apiready = function() {
			var pageParam = api.pageParam;
			pid = pageParam.pid;
			cid = pageParam.cid;
			title = pageParam.title;
			//接收通知
			ReceiveNotifi();
			//开启加载框
			showProgress();
			//加载数据
			loadNewData();
			setRefreshHeader();
			setPullUpRefresh();
		};
		function loadNewData() {
			page = 1;
			loadData();
		}
		function ReceiveNotifi() {
			//发布新评论的通知
			// api.addEventListener({
			// 	name : 'RefreshAddCommentListNotifi'
			// }, function(ret, err) {
			// 	loadNewData();
			// });
			//回复评论的通知
			api.addEventListener({
				name : 'RefreshRepalyCommentNotifi'
			}, function(ret, err) {
				loadNewData();
			});
			api.addEventListener({
			    name: 'refreshCPCommentListNotifi'
			}, function(ret, err) {
			    loadNewData();
			});
		}
		//		接收通知
		function loadMoreData() {
			page++;
			loadData();
		}
		function loadData() {
			var param = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				cid : cid,
				page : page,
				rows : row,
			};
			cfnetppPOST(url_PublicCommentList, param, true, function(data, status) {
				api.refreshHeaderLoadDone();
				hideProgress();
				if (status == 'success') {
					$('#noNet').hide();
					if (data.code == 200) {
						$('#noData').hide();
						var list = data.json.json;
						if (list != null && list.length > 0) {
							$('#noData').hide();
							refreshCount = list.length;
							var listArr = new Array();
							var htmlString = new String();
							if (page == 1) {
								for (var i = 0; i < list.length; i++) {
									var weeklyData = list[i];
									var imgurl = '';
									if (weeklyData.picurl == null) {
										imgurl = '';
									} else {
										imgurl = weeklyData.picurl;
									}
									var data = {
										uid : weeklyData.uid,
										id : weeklyData.id,
										userimg : imgurl,
										username : weeklyData.rename,
										comment : weeklyData.comment,
										score : weeklyData.score,
										ctime : weeklyData.ctime,
										appusername : weeklyData.appusername
									};
									listArr.push(data);
									htmlString += htmlStringWithName(data, i);
								}
								dataArr = listArr;
								$('#list_discus').html(htmlString);
							} else {
								var oldCount = dataArr.length;
								for (var i = 0; i < list.length; i++) {
									var index = oldCount + i;
									var weeklyData = list[i];
									var imgurl = '';
									if (weeklyData.picurl == null) {
										imgurl = '';
									} else {
										imgurl = weeklyData.picurl;
									}
									var data = {
										uid : weeklyData.uid,
										id : weeklyData.id,
										userimg : imgurl,
										username : weeklyData.rename,
										comment : weeklyData.comment,
										score : weeklyData.score,
										ctime : weeklyData.ctime,
										appusername : weeklyData.appusername
									};
									listArr.push(data);
									htmlString += htmlStringWithName(data, index);
								}
								dataArr = dataArr.concat(listArr);
								$('#list_discus').append(htmlString);
							}
						} else {
							if (page == 1) {
								$('#noData').show();
							} else {
								api.toast({
									msg : '暂无数据',
									duration : 2000,
									location : 'bottom'
								});
							}
							$('#list_discus').html('');
						}
					} else {
						if (page == 1) {
							$('#list_discus').html('');
							$('#noData').show();
						}
					}
				} else {
					$('#noNet').show();
				}
			});
		}
		function htmlStringWithName(list, index) {
			var yourString = list.userimg;
			var result = yourString.split("/");
			var img = list.userimg;
			var ctime = list.ctime;
			var comment = "";
			var xingStr = '';
			if (list.appusername == null) {
				comment = list.comment;
			} else {
				comment = "回复@" + list.appusername + ":" + list.comment;
				xingStr = "";
			}
			var deleteString = '';
			var spanStr = '';
			if (list.uid == $api.getStorage('cfnetppuid')) {
				spanStr = '<table class="MBToolBar top_2 ">' + '<tr>' + '<td class="Retweet" onclick="deleteComment(' + list.id + ',' + index + ')"><img class="incon_samll" src="../../image/icon_shanchu.png"/ ><span class="left_5">删除</span></td>' +
					 '<td class="Retweet" id="Reply" style="visibility:hidden;"><img  src="../../image/icon_huifu.png"  class="incon_samll"><span class="left_5">回复</span></td>' +
					  '</tr>' + '</table>';
			    deleteString = '<span class="float-right-span" onclick="deleteComment(' + list.id + ',' + index + ')">'+
								'<img class="delete-img" src="../../image/icon_shanchu.png"/>'+
								'<span>删除</span>'+
							'</span>';
			} else {
				spanStr = '<table class="OneTable top_2 ">' + '<tr>' + '<td class="Retweet " id="Reply" hidden="hidden"><img  src="../../image/icon_huifu.png"  class="incon_samll"> <span class="left_5">回复</span></td>' + '</tr>' + '</table>';
			}
			var score = parseInt(list.score);
			switch(score) {
				case 0:
					xingStr = ""
					break;
				case 1:
					xingStr = '<img src="../../image/icon_xingxing.png" style="height: 14px">' + '<img src="../../image/icon_xingxing01.png"style="height: 14px">' + '<img src="../../image/icon_xingxing01.png"style="height: 14px">' + '<img src="../../image/icon_xingxing01.png"style="height: 14px">' + '<img src="../../image/icon_xingxing01.png"style="height: 14px">';
					break;
				case 2:
					xingStr = '<img src="../../image/icon_xingxing.png" style="height: 14px;">' + '<img src="../../image/icon_xingxing.png"style="height: 14px">' + '<img src="../../image/icon_xingxing01.png"style="height: 14px">' + '<img src="../../image/icon_xingxing01.png"style="height: 14px">' + '<img src="../../image/icon_xingxing01.png"style="height: 14px">';
					break;
				case 3:
					xingStr = '<img src="../../image/icon_xingxing.png" style="height: 14px">' + '<img src="../../image/icon_xingxing.png"style="height: 14px">' + '<img src="../../image/icon_xingxing.png"style="height: 14px">' + '<img src="../../image/icon_xingxing01.png"style="height: 14px">' + '<img src="../../image/icon_xingxing01.png"style="height: 14px">';
					break;
				case 4:
					xingStr = '<img src="../../image/icon_xingxing.png" style="height: 14px"><img src="../../image/icon_xingxing.png"style="height: 14px"><img src="../../image/icon_xingxing.png"style="height: 14px"><img src="../../image/icon_xingxing.png"style="height: 14px"><img src="../../image/icon_xingxing01.png"style="height: 14px">';
					break;
				case 5:
					xingStr = '<img src="../../image/icon_xingxing.png" style="height: 14px">' + '<img src="../../image/icon_xingxing.png"style="height: 14px">' + '<img src="../../image/icon_xingxing.png"style="height: 14px">' + '<img src="../../image/icon_xingxing.png"style="height: 14px">' + '<img src="../../image/icon_xingxing.png"style="height: 14px">';
					break;
				default:
			}
			return '<li dataid="' + index + '" class="mui-table-view-cell mui-media list_item">' +
					'<img class="mui-media-object mui-pull-left cell_user_icon2" src="' + HeadPortraitIsNull(img) + '" style="display: block">' +
					'<p class="base_content_font base_dark_grey" >' +
						'<span>' + 
							list.username + 
						'</span>' + 
						'<span class="font10 left_5">' + 
							"(" + timestampFormat(ctime) + ")" + 
						'</span>' + 
						deleteString+
					'</p>' + 
					'<div class=" clearfix">' + 
						'<div class="star left" id="taiduNum">' + 
							xingStr + 
						'</div>' + 
					'</div>' + 
					'<div class="Commentbody top_2 ">' + 
						'<p >' + 
							comment + 
						'</p>' + 
					'</div>' + 
					// spanStr + 
				'</li>';
		}
		//删除评论
		function deleteComment(id,index) {
			var data = dataArr[parseInt(index)];
			api.openFrame({
				name : 'Study_CompetitiveProductsCommentDelete',
				url : 'Study_CompetitiveProductsCommentDelete.html',
				pageParam : {
					id : id,
					cid : cid,
				}
			});
		}
		//回复评论
		function openReply(index) {
			var data = dataArr[parseInt(index)];
			api.openFrame({
				name : 'Study_CompetitiveProductsReplyComment',
				url : 'Study_CompetitiveProductsReplyComment.html',
				pageParam : {
					data : data,
					cid : cid,
				}
			});
		}
		// //添加新评论
		// function AddComment() {
		// 	api.openFrame({ 
		// 		name : 'Study_CompetitiveProductsAddComment',
		// 		url : 'Study_CompetitiveProductsAddComment.html',
		// 		pageParam : {
		// 			cid : cid,
		// 			pid : pid,
		// 			title : title
		// 		}
		// 	});
		// }
		function onEditCommentClick(){
			api.openFrame({
			    name: 'Study_CompetitiveProductsEditComment',
			    url: 'Study_CompetitiveProductsEditComment.html',
			    pageParam: api.pageParam,
			    bounces: false
			});
			api.setFrameAttr({
				name : 'Study_CompetitiveProductsEditComment',
				hidden : false
			});
		}
	</script>
</html>